<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/aaa/layuiadmin/layui/layui.js"></script>
    <link rel="stylesheet" href="/aaa/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/aaa/layuiadmin/style/admin.css" media="all">

</head>
<body>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script src="/aaa/layuiadmin/layui/layui.js"></script>
    <link rel="stylesheet" href="/aaa/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/aaa/layuiadmin/style/admin.css" media="all">

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">电瓶地点</label>
                    <div class="layui-input-block">
                        <input type="text" name="addName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">经度</label>
                    <div class="layui-input-block">
                        <input type="text" name="longitude" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">纬度</label>
                    <div class="layui-input-block">
                        <input type="text" name="dimensionality" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">


            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="batteryManger">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>

            </script>
            <script type="text/html" id="batteryList">
                {{d.LAY_TABLE_INDEX+1}}
            </script>
        </div>
    </div>
</div>
<!---------------添加弹出框---------------------------------->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiBattery-form-batteruInfo"
     style="padding: 20px 0 0 0;display: none">
    <div class="layui-form-item">
        <label class="layui-form-label">电瓶地点</label>
        <div class="layui-input-inline">
            <input type="text" name="addName" lay-verify="" placeholder="请输入地点名称" autocomplete="off"
                   class="layui-input">
        </div>

        <label class="layui-form-label">经度</label>
        <div class="layui-input-inline">
            <input type="text" name="longitude" lay-verify="" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>

        <label class="layui-form-label">纬度</label>
        <div class="layui-input-inline">
            <input type="text" name="dimensionality" lay-verify="" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>
        <div  class="layui-inline">
        <label class="layui-form-label">电瓶总数</label>
        <div class="layui-input-inline">
            <input type="text" name="batterySum" lay-verify="" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>

        <label class="layui-form-label">学校</label>
        <div class="layui-input-inline">
            <input id="schoolName" type="text" name="schoolId" lay-verify="" placeholder="请输入学校代号" autocomplete="off"
                   class="layui-input">
        </div>
        </div>
        <div id="batteryAddressInfo"  class="layui-layer-btn layui-layer-btn-">
            <a class="layui-layer-btn0" lay-submit lay-filter="batteryinfo-submit">确定</a>
            <a class="layui-layer-btn1">取消</a>
        </div>

    </div>

    <!------------------------------>
    <div class="layui-fluid">
        <div class="layui-card">

            <table id="school_name" lay-filter="LAY-user-manage-batteryinfo"></table>
            <script type="text/html" id="addList">
                {{d.LAY_TABLE_INDEX+1}}
            </script>
        </div>
    </div>

</div>
<!-----------------^^^^添加弹出框^^^^------------------------------------------>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin-edit" id="layuiBattery-form-batteruInfo-eidt"
     style="padding: 20px 0 0 0;display: none">
    <div class="layui-form-item">
        <label class="layui-form-label">电瓶地点</label>
        <div class="layui-input-inline">
            <input type="text" name="addName" lay-verify="" placeholder="请输入地点名称" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline layui-hide">
            <input type="text" name="pid" lay-verify="" autocomplete="off"
                   class="layui-input">
        </div>

        <label class="layui-form-label">经度</label>
        <div class="layui-input-inline">
            <input type="text" name="longitude" lay-verify="" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>

        <label class="layui-form-label">纬度</label>
        <div class="layui-input-inline">
            <input type="text" name="dimensionality" lay-verify="" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>

        <label class="layui-form-label">电瓶总数</label>
        <div class="layui-input-inline">
            <input type="text" name="batterySum" lay-verify="" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>

        <label class="layui-form-label">学校</label>
        <div class="layui-input-inline">
            <input type="text" name="schoolId" lay-verify="" placeholder="请输入学校代号" autocomplete="off"
                   class="layui-input">
        </div>


        <div id="batteryAddressInfo-edit" class="layui-layer-btn layui-layer-btn-">
            <a class="layui-layer-btn0" lay-submit lay-filter="batteryinfo-edit">确定</a>
            <a class="layui-layer-btn1">取消</a>
        </div>
    </div>
</div>
<!------------------------------>
</div>

<script>
    layui.use(['laytpl', 'table', 'form'], function () {
        var $ = layui.$
            , form = layui.form
            , laytpl = layui.laytpl
            , table = layui.table;
        table.render({
            elem: '#LAY-user-manage',
            height: 600,
            url: '/aaa/battery/getbatteryinfo',
            page: true,
            cols: [
                [
                    {field: 'battery', title: '编号', align: 'center', templet: '#batteryList'},
                    {field: 'addName', title: '电瓶地点', align: 'center'},
                    {field: 'longitude', title: '经度', align: 'center'},
                    {field: 'dimensionality', title: '纬度', align: 'center'},
                    {field: 'batterySum', title: '站点电瓶总数', align: 'center'},
                    {field: 'batteryQuantity', title: '可用电瓶数', align: 'center'},
                    {field: 'school', title: '学校名', align: 'center'},
                    {field: 'pid', title: '主键', align: 'center'},
                    {title: '操作', toolbar: '#batteryManger', align: 'center'},
                ]
            ] , done: function (res, curr, count) {
                $(".layui-table-box").find("[data-field='pid']").css("display", "none");
                $(".layui-table-box").find("[data-field='schoolId']").css("display", "none");
            }
        });
        //输入学校代号或名称
        $('#schoolName').on('input propertychange', function (e) {
            var s = document.getElementById('schoolName').value;
            table.render({
                elem: '#school_name',
                height: 312,
                url: '/aaa/battery/getschools?school=' + s,
                page: true,
                cols: [
                    [
                        {field: 'add', title: '编号', fixed: 'center', templet: '#addList'},
                        //{field: 'schoolId', title: '学校代号', align: 'center'},
                        {field: 'school', title: '学校名', align: 'center'},
                        {field: 'schoolId',title:'学校代码' ,align: 'center'},
                    ]
                ]
                // 隐藏列
                , done: function (res, curr, count) {
                    $(".layui-table-box").find("[data-title='学校代号']").css("display", "none");
                }

            });
        });


        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-user-manage', {
                where: field
            });
        });
        //
        table.on('tool(LAY-user-manage)', function (obj) {
            /*  var checkStatus = table.checkStatus(obj.config.id);*/
            var data = obj.data;

            if (obj.event === 'edit') {
                form.val('layuiadmin-form-useradmin-edit', {
                    'addName': data.addName,
                    'longitude': data.longitude,
                    'dimensionality':data.dimensionality,
                    'schoolId':data.schoolId,
                    'pid':data.pid,
                    'batterySum':data.batterySum,
                })
                    ,layer.open({
                    type: 1
                    , title: '添加'
                    , content: $('#layuiBattery-form-batteruInfo-eidt')
                    , area: 'auto'
                });
            }else if(obj.event === 'del'){
                layer.confirm('确定删除吗？', function (index) {
                    $.ajax({
                        url:'/aaa/battery/delbatteryinfo',
                        type:'POST',
                        data:{
                            id:data.pid
                        },
                        success:function(data){
                            table.reload('LAY-user-manage');
                            layer.msg(data.msg);
                        }
                    });


                });

            }

        });
        form.on('submit(batteryinfo-edit)',function (data) {
            var data = data.field;
            $.ajax({
                type:'post',
                url:'/aaa/battery/updatebatteryinfo',
                data:data,
                success:function (data) {
                    layer.msg(data.msg);
                    table.reload('LAY-user-manage');
                }
            });
        });
        //事件
        var active = {
             add: function () {
                layer.open({
                    type: 1
                    , title: '添加'
                    , content: $('#layuiBattery-form-batteruInfo')
                    , area: ['1500px', '600px']
                    , end: function () {
                        window.location.reload();
                    }
                });

            }
        };
        form.on('submit(batteryinfo-submit)', function (data) {
            var param = data.field;
            $.ajax({
                url: '/aaa/battery/addbatteryinfo',
                type: 'POST',
                data: param,
                success: function (data) {
                    layer.msg(data.msg);
                }

            })
        });

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>

</body>
</html>